/**
 * @Date 2025/1/19 20:44
 * @Created by 衡盛永
 */

package com.shangting.common.interceptor;

import com.shangting.common.login.LoginUserHolder;
import com.shangting.common.login.LoginUser;
import com.shangting.common.utils.JwtUtil;
import io.jsonwebtoken.Claims;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//springboot3的路径是：
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//而 springboot2的路径是：
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;


//@Component
public class AuthenticationInterceptor implements HandlerInterceptor {
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//
//        String token = request.getHeader("access-token");
//
//        Claims claims = JwtUtil.parseToken(token);
//        Long userId = claims.get("userId", Long.class);
//        String username = claims.get("username", String.class);
//        LoginUserHolder.setLoginUser(new LoginUser(userId, username));
//
//        return true;
//
//    }
//
//    @Override
//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//        LoginUserHolder.clear();
//    }
}
